package com.ld.control.business.equipment.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ld.control.business.equipment.mapper.EquipmentHolePositionConvertMapper;
import com.ld.control.business.equipment.model.EquipmentHolePositionConvertModel;
import com.ld.control.business.equipment.service.EquipmentHolePositionConvertService;
import com.ld.control.business.equipment.vo.req.EquipmentHolePositionConvertReqVo;
import com.ld.control.business.equipment.vo.resp.EquipmentHolePositionConvertRespVo;
import com.ld.control.common.vo.GeneratePageListVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 设备孔位映射表 服务实现类
 * </p>
 *
 * @author wangfeng
 * @since 2025-06-20
 */
@Service
public class EquipmentHolePositionConvertServiceImpl extends ServiceImpl<EquipmentHolePositionConvertMapper, EquipmentHolePositionConvertModel> implements EquipmentHolePositionConvertService {

    @Autowired
    private EquipmentHolePositionConvertMapper equipmentHolePositionConvertMapper;

    @Override
    public Map<Integer, EquipmentHolePositionConvertModel> getMap(Long equipmentId) {
        Map<Integer, EquipmentHolePositionConvertModel> respMap = new HashMap<>();
        List<EquipmentHolePositionConvertModel> equipmentHolePositionConvertList = equipmentHolePositionConvertMapper.selectListByEquipmentId(equipmentId);
        for (EquipmentHolePositionConvertModel data: equipmentHolePositionConvertList) {
            respMap.put(data.getHolePosition(), data);
        }
        return respMap;
    }

    @Override
    public void add(EquipmentHolePositionConvertReqVo reqVo) {
        EquipmentHolePositionConvertModel equipmentHolePositionConvertModel = new EquipmentHolePositionConvertModel();
        BeanUtils.copyProperties(reqVo, equipmentHolePositionConvertModel);
        equipmentHolePositionConvertMapper.insert(equipmentHolePositionConvertModel);
    }

    @Override
    public void updateById(EquipmentHolePositionConvertReqVo reqVo) {
        EquipmentHolePositionConvertModel equipmentHolePositionConvertModel = new EquipmentHolePositionConvertModel();
        BeanUtils.copyProperties(reqVo, equipmentHolePositionConvertModel);
        equipmentHolePositionConvertMapper.updateById(equipmentHolePositionConvertModel);
    }

    @Override
    public void deleteById(Long id) {
        equipmentHolePositionConvertMapper.deleteById(id);
    }

    @Override
    public EquipmentHolePositionConvertRespVo getById(Long id) {
        EquipmentHolePositionConvertRespVo respVo = new EquipmentHolePositionConvertRespVo();
        EquipmentHolePositionConvertModel equipmentHolePositionConvertModel = equipmentHolePositionConvertMapper.selectById(id);
        BeanUtils.copyProperties(equipmentHolePositionConvertModel, respVo);
        return respVo;
    }

    @Override
    public GeneratePageListVo<EquipmentHolePositionConvertRespVo> getPageList(Long equipmentId, Integer current, Integer size) {
        IPage<EquipmentHolePositionConvertRespVo> iPage = new Page<>(current, size);
        IPage<EquipmentHolePositionConvertRespVo> iPage1 = equipmentHolePositionConvertMapper.selectPageList(iPage, equipmentId);
        return new GeneratePageListVo<>(iPage1);
    }
}
